package edu.pku.sei.autounit.reflect.jdt;

import java.util.Map;

import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;

import edu.pku.sei.autounit.reflect.AbstractType;
import edu.pku.sei.autounit.reflect.Enum;
import edu.pku.sei.autounit.util.Log;

public class JDTEnum extends AbstractType implements Enum{

	private String fullName;
	private String name;
	private String []constantNames;
	protected JDTEnum(IType jdtType){
		this.fullName = jdtType.getFullyQualifiedName().replace('$','.');
		this.name = jdtType.getTypeQualifiedName().replace('$','.');
		try {
			IField [] ifs = jdtType.getFields();
			this.constantNames = new String[ifs.length];
			for(int i = 0;i<ifs.length;i++)
				constantNames[i] = ifs[i].getElementName();
		} catch (JavaModelException e) {
			Log.gotUnexpectedExection("JDTEnum", "JDTEnum", "", e);
		}
	}

	
	public String getName(Map<String,String> map) {
		if(fullName.startsWith("java.lang"))
			return name;
		String f = map.get(name);
		if(f == null){
			map.put(name, fullName);
			return name;
		}
		else if(f.equals(fullName))
			return name;
		else
			return fullName;
	}
	
	
	public String getFullName() {
		return fullName;
	}
	
	
	public String[] getEnumConstants() {
		return constantNames;
	}
	
}
